package io.renren.modules.knowledge.respository;

import io.renren.modules.knowledge.entity.node.knowledge;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface KnowledgeRespository extends Neo4jRepository<knowledge,Long> {

    @Query("match (c:course) where id(c) = {startId} match (c2:course) where id(c2) = {endId} with c,c2  create (c)-[:progressively]->(c2) return c,c2")
    void saveCoursesRelactionShip(@Param("startId") Long startId,@Param("endId") Long endId);
    @Query("match (c:course) where id(c) = {deleteId} with c  match (c)-[r]-() delete c,r")
    void delCourseAndShip(@Param("deleteId") Long deleteId);
    @Query("match (c:course) where id(c) = {deleteId} with c  match (c)-[r]-() delete c,r")
    void delCourseAndShipNoNodes(@Param("deleteId")Long deleteId);

    @Query("match (c:knowledge) where id(c) = {startId} with c  match (c)-[r]-() delete c,r")
    void delKnowledgeAndRelationShip(@Param("startId")Long startId);
    @Query("match (c:course) where id(c) = {startId} match (c2:course) where id(c2) = {endId} with c,c2  create (c)-[:outProgressively]->(c2) return c,c2")
    void addNoOneKnowledgePointRelationship(@Param("startId")Long startId, @Param("endId")Long endId);
    @Query("match (c:course) where id(c) = {courseId} match (k:knowledge) where id(k) = {knowledgeId} with c,k create (c)-[:contain]->(k)")
    void saveKnowledgeInCourseRelationship(@Param("courseId")Long courseId, @Param("knowledgeId")Long knowledgeId);
    @Query("match (c:knowledge) where id(c) = {startId} match (c2:knowledge) where id(c2) = {endId} with c,c2  create (c)-[:progressively]->(c2) return c,c2")
    void addKnowledgePointRelationship(@Param("startId")Long startId,@Param("endId") Long endId);
}
